/*
脚本说明:角色权限维护，角色扩展权限列表。
程序员:
*/

//脚本唯一关键字,通过该关键字找到对应脚本，每个脚本必须有该描述。
var v_script_id = 'authroleinfos_dyna';
//脚本状态,0:该脚本不许执行，1:该脚本可以执行
var v_status = '1';

//脚本逻辑写在run语句之间
if (run){
	var user = action.getSession().getAttribute("user");
	var authid = action.form.getInteger('authid');
	var sql = 'select * from h_auth_dyna where authid=' + authid;
	var map = action.dbUtil.findFirst("", sql);
	var tablename = map.get('tname');
	var vcol = map.get('vcol');
	var pcol = map.get('pcol');
	var condition = map.get('condition');
	
	
	action.vars.put(action.V_TABLE_NAME,'v_auth_dyna_role_infos');//指定获取数据的表名
	action.vars.put(action.V_MAX_LINE,'20');//每页显示多少条
	
	if(user.getRolekind()<3){
		action.vars.put(action.V_CONDITION, 'where authid=' + authid + ' order by id desc' );
	}else{
		action.vars.put(action.V_CONDITION, 'where authid=' + authid + 
				' and roleid in(select id from h_auth_roles where userid=' +user.getId() +  
				') order by id desc' );
	}
	//扩展字段的做法 
	//var expandsql = ' select ' + vcol + ' as vcol from ' + tablename + ' where ' + pcol + ' = #pcolvalue# ' ;
	//action.vars.get(action.V_EXPEND_COLUMN).put('vcolvalue', expandsql); //扩展字段
	//映射字段的做法
	var mapsql = ' select ' + vcol +' , ' +  pcol + ' from ' + tablename  + ' ' + condition ;
	//println(mapsql);
	var vcolmap = action.buildHashMap(mapsql, pcol, vcol, 1 );
	vcolmap.put(action.V_MAPED_COLUMN,'pcolvalue');//取state的值当key
	action.vars.get(action.V_MAP_COLUMN).put('vcolvalue',vcolmap);
	
	
	//action.vars.put(action.V_OUTPUT_FILE_FORMAT,'3');
	
	
}